package com.gw.smscheck.service.business.comefrom.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gw.smscheck.dao.business.comefrom.JzfdVisitorTopFromMapper;
import com.gw.smscheck.entity.business.comefrom.JzfdVisitorTopFrom;
import com.gw.smscheck.service.business.comefrom.JzfdVisitorTopFromService;
import com.gw.smscheck.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Time;
import java.util.List;

@Service
public class JzfdVisitorTopFromServiceImpl implements JzfdVisitorTopFromService {
    @Autowired
    private JzfdVisitorTopFromMapper visitorTopFromMapper;

    @Override
    public List<JzfdVisitorTopFrom> findAll() {
        return visitorTopFromMapper.findAll();
    }

    @Override
    public PageInfo<JzfdVisitorTopFrom> pageSelect(JzfdVisitorTopFrom dto) {
        PageHelper.startPage(dto.getPage(), dto.getRows(), "create_time desc");// 排序
        List<JzfdVisitorTopFrom> resultList = visitorTopFromMapper.pageSelect(dto);
        PageInfo<JzfdVisitorTopFrom> pageInfo = new PageInfo<>(resultList);
        return pageInfo;
    }

    @Override
    public Time findEndTime(JzfdVisitorTopFrom dto) {
        if (StringUtils.isBlank(dto.getNowTime())) {
            dto.setNowTime(DateUtil.getCurrDate("HH:mm:ss"));
        }
        return visitorTopFromMapper.findEndTime(dto);
    }

    @Override
    public List<JzfdVisitorTopFrom> findCurrent(JzfdVisitorTopFrom dto) {
        dto.setCalledDate(DateUtil.getCurrDate("yyyy-MM-dd"));
        dto.setNowTime(DateUtil.getCurrDate("HH:mm:ss"));
        Time time = findEndTime(dto);
        if (time != null) {
            dto.setEndTime(time);
        }
        return visitorTopFromMapper.findByModal(dto);
    }

    @Override
    public List<JzfdVisitorTopFrom> findByModal(JzfdVisitorTopFrom dto) {
        dto.setNowTime(DateUtil.getCurrDate("HH:mm:ss"));
        Time time = findEndTime(dto);
        if (time != null) {
            dto.setEndTime(time);
        }
        return visitorTopFromMapper.findByModal(dto);
    }
}
